<?php  
/**
* 简历第四阶段
*/
class Resume4Model extends Model
{
	public $table='people_resume4';

	//定义规则
	public $validate = array(
		array("starttime", "regexp:/^\d{4}-\d{1,2}-\d{1,2}$/", "开始时间格式不正确", 2, 3),
        array("endtime", "regexp:/^\d{4}-\d{1,2}-\d{1,2}$/", "结束时间格式不正确", 2, 3),
        array("schoolname", "maxlen:30", "学校名称不得超过30字", 2, 3),
        array("skillname", "maxlen:30", "专业名称不得超于30字", 2, 3),
        array("edu", "num:1,9", "请选择学历", 2, 3),

		);

	public $auto = array(
		array('resume1_reid','_reid','method',2,1)
		);


	public function _reid(){

		return Q('post.reid', 0, 'intval');

	}


	public function have_data($reid)
	{
		return $this->where('resume1_reid = '.$reid)->getField('resume1_reid');
	}


	public function add_data()
	{
		$reid = Q('post.reid');
		if($this->where('resume1_reid = '.$reid)->count() > 2){
			$this->error='教育经历不得超过2个';
			return false;
		}


		return $this->add();
	}


	public function get_data($reid4)
	{
		return $this->where(array('resume1_reid' => $reid4))->all();
	}


	public function del_data($reid4,$reid)
	{
		$where = array(
				'reid4'=>$reid4,
				'resume1_reid'=>$reid
			);
		$row = $this->where($where)->del();
		// echo $this->getLastSql();exit;

		if($row > 0){
			return true;
		}else{
			$this->error('参数错误');
			return false;
		}
	}


	public function get_data_by_id($reid4,$reid)
	{
		$res = $this->where(array('reid4'=>$reid4,'resume1_reid' => $reid))->find();
		if ($res) {
			return $res;
		}

		$this->error = '非法参数';
		return false;
	}


	public function update_data($reid4,$reid)
	{
		$where = array(
				'reid4'=>$reid4,'resume1_reid' => $reid
			);
		return $this->where($where)->save();
	}
}

?>